In present day multi-platform computing environments, it is often a requirement that programs written in one language have to interact with programs written in another language (e.g. a computer program from Java.TM. making use of a C library). A prime difficulty with the interaction of programs written in different computer programming languages is the representation of data--each language stores information differently. If two programs are to interact, one program must convert the data from the representation used by the other program to its own.
The Java.TM. Native Interface (JNI) Application Programming Interface (API) is provided in the Java.TM. programming language to call C functions as if they were written in Java.TM.. The Java.TM. Native Interface also provides a set of functions for converting primitive data types. While this is an elegant solution from a Java.TM. code perspective, it results in an interface which is extremely difficult to understand and to use from a C code perspective. It is well known in the art that typical computer programs use complex data structures built from the primitive data types. The JNI does not provide a method for automating the conversion of complex data structures. Also, complexity of this interface practically ensures that faults will find their way into applications where native methods are used. The danger presented by these faults is extreme since the native method interface allows C functions to access pointers to memory residing inside a Java.TM. virtual machine (VM).
The Java.TM. VM is intended to present an abstract, logical machine design free from the distraction of inconsequential details of any implementation. The memory areas of the Java.TM. virtual machine do not presuppose any particular locations in memory or locations with respect to one another. The memory areas need not consist of contiguous memory. However, the instruction set, registers, and memory areas are required to represent values of certain minimum logical widths (e.g. the Java.TM. stack is 32 bits wide). These requirements are discussed in the following sections.
The Java.TM. virtual machine is a machine which runs a special set of instructions which specify every possible instruction which may be implemented by the machine. The Java.TM. VM allows every computer to run Java.TM. applications. A pointer is a data item which specifies a location of another data item. Pointers are very unstable and therefore their use can lead to unstable computer operations, which can lead to a possible crash of the entire Java.TM. VM.
To reduce the complexity of implementing native methods, and to minimize the number of places where pointers to memory within the Java.TM. VM are accessed, the inventors have recognized the desirability of providing a means to convert objects (or even primitive data types) used in legacy function calls (i.e. function calls provided by existing programs). In software, a legacy system is an existing system to which new code is being added and a legacy function is a function used in such a system. By localizing this conversion to a single location, much of the danger inherent in the use of native methods can be mitigated.